/**
filename: w25qxx_spi.h
author: Mr.GAO
website: www.genbotter.com
version: V1.0

instructions of w25qxx
**/
#ifndef _W25QXX_SPI_H
#define _W25QXX_SPI_H

#include "gd32f10x.h"
#include "spi_w25qxx_ins.h"
#include "gd32f10x_spi.h"

#define W25QXX_ID_1           1
#define W25QXX_SR_ID_1        1
#define W25QXX_SR_ID_2        2
#define W25QXX_SR_ID_3        3

void w25qxx_init(void);
// 使能外设时钟
void w25qxx_rcu_init(void);	
// IO口进行配置，使之复用为SPI0， PA4\PA5\PA6\PA7，NSS\SCK\MISO\MOSI
void w25qxx_io_init(void);
// SPI0初始化
void w25qxx_spi_init(void);

void w25qxx_wait_busy(void);
uint8_t w25qxx_read_sr(uint8_t sregister_id);  // 读状态寄存器
void w25qxx_read_id(uint8_t *MID, uint16_t *DID);

void w25qxx_read(uint8_t *p_buffer, uint32_t read_addr, uint16_t num_read_bytes);

void w25qxx_write(uint8_t *p_buffer, uint32_t write_addr, uint16_t num_write_bytes);
void w25qxx_write_nocheck(uint8_t *p_buffer, uint32_t write_addr, uint16_t num_write_bytes); //
void w25qxx_write_page(uint8_t *p_buffer, uint32_t write_addr, uint16_t num_write_bytes);   // page program

void w25qxx_erase_sector(uint32_t sector_addr);
void w25qxx_erase_chip(void);

void w25qxx_write_enable(void);
void w25qxx_write_disable(void);

void w25qxx_power_down(void);
void w25qxx_wake_up(void);

void w25qxx_cs_enable(uint8_t cs_id);
void w25qxx_cs_disable(uint8_t cs_id);
uint8_t w25qxx_swap(uint8_t byte_to_send);
void w25qxx_printdata(uint32_t beg_addr, uint32_t len);

#endif
